package github.flandre.examplemod;

import github.flandre.examplemod.client.gui.DisplayCaseScreen;
import github.flandre.examplemod.common.config.exampleconfig;
import github.flandre.examplemod.common.guiblock.GuiBlockInit;
import github.flandre.examplemod.common.guiblock.Screen.ExampleBurnMachineScreen;
import github.flandre.examplemod.common.key.KeyBandinglist;
import github.flandre.examplemod.core.init.*;
import github.flandre.examplemod.core.init.event.EntitySpawnEvent;
import github.flandre.examplemod.core.init.event.OreGenerationEvent;
import github.flandre.examplemod.network.NetworkRegistryHandler;
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.potion.Effect;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.server.permission.DefaultPermissionLevel;
import net.minecraftforge.server.permission.PermissionAPI;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(examplemod.MODID)
public class examplemod {
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MODID = "examplemod";
    public examplemod() {

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
        //加入注册对象 把items注册到
        ItemInit.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        //加入方块注册
        BlockInit.BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());


        GuiBlockInit.BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
        GuiBlockInit.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());


        EnchantmentInit.ENCHANTS.register(FMLJavaModLoadingContext.get().getModEventBus());

        //创建药水效果
        EffectInit.EFFECTS.register(FMLJavaModLoadingContext.get().getModEventBus());
        //创建药水瓶实例
        PotionInit.POTION_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
        EntityInit.ENCHANTS.register(FMLJavaModLoadingContext.get().getModEventBus());

        //手动注册世界生成生物
        MinecraftForge.EVENT_BUS.addListener(
                EventPriority.HIGH,
                EntitySpawnEvent::BiomeLoading);

        //手动注册世界生成矿物
        MinecraftForge.EVENT_BUS.addListener(
                EventPriority.HIGH,
                OreGenerationEvent::generateOres);

        //注册网络发包
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onCommonSetUp);
        //机器实体的注册
        TileEntityInit.TILE_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
        //界面注册
        ContainerInit.CONTAINERS_TYPE.register(FMLJavaModLoadingContext.get().getModEventBus());
        //机器注册
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup);

        //权限注册
        PermissionAPI.registerNode("a.random.permission.key", DefaultPermissionLevel.OP, "My first permission");


        //注册config
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, exampleconfig.SPEC,"example-common.toml");


    }

    public void onCommonSetUp(FMLCommonSetupEvent event)
    {
        NetworkRegistryHandler.registerMessage();
        //注册完之后需要同步一下数据 玩家加入的时候 玩家死亡 增加数值时[怪物受到伤害]
    }

    public void onClientSetup(FMLCommonSetupEvent event)
    {
        //绑定注册GUI 一个是实体界面 一个是渲染贴图
        ScreenManager.registerFactory(ContainerInit.EXAMPLE_GUI_CONTAINER.get(),
                DisplayCaseScreen::new);

        ScreenManager.registerFactory(ContainerInit.obsidianFirstContainer.get(),
                ExampleBurnMachineScreen::new);


    }

}
